﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Centrica.TaskManager.Data;

namespace Centrica.TaskManager.Tests.Task
{
    [TestClass]
    public class TaskCommands
    {

        [TestMethod]
        public void ExecuteEditTaskCommand_FireEditCommand()
        {
            var tasksViewModel = new TasksViewModelMock();
            
            bool editTaskFired = false;

            tasksViewModel.EditTaskFired += delegate { editTaskFired = true; };
                        
            tasksViewModel.EditTaskCommand.Execute(CreateTask());

            Assert.IsTrue(editTaskFired, "Edit Task Command Failed");
        }

        [TestMethod]
        public void DeleteTaskCommand_FireDeleteCommand()
        {
            var tasksViewModel = new TasksViewModelMock();

            bool deleteTaskFired = false;

            tasksViewModel.DeleteTaskFired += delegate { deleteTaskFired = true; };

            tasksViewModel.DeleteTaskCommand.Execute(CreateTask());

            Assert.IsTrue(deleteTaskFired, "Delete Task Command Failed");
        }

        [TestMethod]
        public void AddTaskCommand_FireAddCommand()
        {
            var tasksViewModel = new TasksViewModelMock();

            bool addTaskFired = false;

            tasksViewModel.EditTaskFired += delegate { addTaskFired = true; };

            tasksViewModel.EditTaskCommand.Execute(CreateTask());

            Assert.IsTrue(addTaskFired, "Add Task Command Failed");
        }

        [TestMethod]
        public void SaveTaskCommand_FireSaveTaskCommand()
        {
            var taskViewModel = new TaskViewModelMock();

            bool saveTaskFired = false;

            taskViewModel.SaveTaskFired += delegate { saveTaskFired = true; };

            taskViewModel.SaveTaskCommand.Execute(CreateTask());

            Assert.IsTrue(saveTaskFired, "Save Task Command Failed");
        }

        private Centrica.TaskManager.Data.Task CreateTask()
        {

            Centrica.TaskManager.Data.Task task = new Centrica.TaskManager.Data.Task();

            task.TaskId = 1;
            task.TaskName = "Test Task";

            TaskStatus taskStatus = new TaskStatus();

            taskStatus.TaskStatusId = 1000;
            taskStatus.TaskStatusName = "Test Status";
            taskStatus.TaskStatusDescription = "Test Status Description";

            task.TaskStatus = taskStatus;

            TaskType taskType = new TaskType();
            taskType.TaskTypeId = 30;
            taskType.TaskTypeName = "Test TaskType";
            taskType.TaskTypeDescription = "Test TaskType Description";

            task.TaskType = taskType;

            task.EndDate = DateTime.Now.AddMonths(1);
            task.StartDate = DateTime.Now;

            task.TmsChange = DateTime.Now;
            task.UserName = "Test User";

            return task;

        }

    }
}
